const mysql=require("mysql")//引入数据库

module.exports=(sql,params=[])=>{
    const connection=mysqi.createConnection({
        host:"localhost",
        user:"root",
        password:"mysqlroot",
        database:"1711b"
    })
}


 //连接数据库
    connection.connect(error=>{
        if(error) throw error
        console.log('数据库连接成功')
    });
    
    return new Promise((resolve, reject) => {
        //查询数据库
        connection.query(sql,params, function (error, results, fields) {
               if(error){
                   reject(error)
               }else{
                   resolve(results)
               }
        });
        //关闭数据库
        connection.end();
    })
    
}

